package com.shanzmoo.core.domain.pay;

import com.shanzmoo.db.trade.entity.PayOrderBodyEntity;
import com.shanzmoo.db.trade.entity.PayOrderEntity;

/**
 * 支付单对象线程工具类
 * @author: Gzhao 2020/12/11
 */
public class PayOrderEntityLocalUtil {

    private static ThreadLocal<PayOrderEntity> payOrderEntity = new ThreadLocal<>();
    private static ThreadLocal<PayOrderBodyEntity> payOrderBodyEntity = new ThreadLocal<>();

    public static void initOrder(PayOrderEntity payOrder) {
        payOrderEntity.set(payOrder);
        payOrderBodyEntity.set(PayOrderBodyEntity.create(payOrder.getPayNo()));
    }

    public static void setPayOrder(PayOrderEntity payOrder, PayOrderBodyEntity payOrderBody) {
        payOrderEntity.set(payOrder);
        payOrderBodyEntity.set(payOrderBody);
    }



    public static PayOrderEntity getPayOrderEntity() {
        return payOrderEntity.get();
    }

    public static PayOrderBodyEntity getPayOrderBodyEntity() {
        return payOrderBodyEntity.get();
    }

    public static void setReqBody(String reqBody) {
        if (payOrderBodyEntity.get() != null){
            payOrderBodyEntity.get().setReqBody(reqBody);
        }
    }

    public static void setRespBody(String body) {
        if (payOrderBodyEntity.get() != null){
            payOrderBodyEntity.get().setRespBody(body);
        }
    }

    public static void setQueryRespBody(String body) {
        if (payOrderBodyEntity.get() != null){
            payOrderBodyEntity.get().setQueryRespBody(body);
        }
    }

    public static void setOrderStatus(boolean status) {
        if (payOrderEntity.get() != null){
            payOrderEntity.get().setStatus(status);
        }
    }

    public static void clear() {
        payOrderEntity.remove();
        payOrderBodyEntity.remove();
    }
}
